package net.chathu.airgw.packets.chat 
{
	import net.chathu.airgw.Config;
	import net.chathu.airgw.packets.gw.serverpackets.EchoPacket;
	import net.chathu.airgw.packets.gw.serverpackets.HostAndVersionPacket;
	import net.chathu.airgw.packets.gw.serverpackets.ISupportPacket;
	import net.chathu.airgw.packets.gw.serverpackets.LUsersPacket;
	import net.chathu.airgw.packets.gw.serverpackets.ModePacket;
	import net.chathu.airgw.packets.gw.serverpackets.MOTDPacket;
	import net.chathu.airgw.packets.gw.serverpackets.MOTDStartPacket;
	import net.chathu.airgw.packets.gw.serverpackets.MOTDStopPacket;
	import net.chathu.airgw.packets.gw.serverpackets.ServerCreatedDatePacket;
	import net.chathu.airgw.packets.gw.serverpackets.WelcomePacket;

	/**
	 * ...
	 * @author ze
	 */
	public class Time extends ChatPacket 
	{
		
		public function Time() 
		{
			
		}
		
		override public function execute():void
		{
			var y:int,m:int,d:int,hour:int,min:int,sec:int;
			y=parseInt( (data[1]).substring(0, 4) );
			m=parseInt( (data[1]).substring(4, 6) );
			d=parseInt( (data[1]).substring(6, 8) );
			hour=parseInt( (data[1]).substring(8, 10) );
			min=parseInt( (data[1]).substring(10, 12) );
			sec = parseInt( (data[1]).substring(12, 14) );
			
			var time:String = "(" + y + "." + m + "." + d + ".) " + hour + ":" + min + ":" + sec; 
			
			//sendToClient(new WelcomePacket(sessionData.nick,sessionData.nick,"localhost"));
			sendToClient(new WelcomePacket(sessionData.nick,sessionData.yourHost));
			sendToClient(new HostAndVersionPacket(sessionData.nick, Config.PROGRAM_NAME + " " + Config.PROGRAM_VERSION));
			sendToClient(new ServerCreatedDatePacket(sessionData.nick));
			sendToClient(new ISupportPacket(sessionData.nick, "RFC2812 PREFIX=(aohv)~@%+ CHANTYPES=#& NICKLEN=64 :are supported by this server"));
			//_session.SessionData().getClientSocketHandler().sendPacketToClient(new ServerInfoPacket(MasterServerConnection.getGWHostname(), _session.SessionData().getCurrentNick()));
			
			sendToClient(new MOTDStartPacket(sessionData.nick));
			/*Vector motd=Config.getMOTDMessages();
			Iterator i=motd.iterator();
			while(i.hasNext())
			{
				String motdline=(String)i.next();
				_session.SessionData().getClientSocketHandler().sendPacketToClient(new MOTDPacket(MasterServerConnection.getGWHostname(),_session.SessionData().getCurrentNick(),motdline));
			}*/
			
			var motdMessages:Array = Config.MOTD.split("\n");
			for each(var line:String in motdMessages)
			{
				sendToClient(new MOTDPacket(sessionData.nick, line));
			}
			sendToClient(new MOTDStopPacket(sessionData.nick));
			
			//ez kell sok kliensnek:
			sendToClient(new ModePacket(sessionData.nick,"+"));
			
			/*
		    for(int cc=0; cc<Config._autojoinchannels.length;cc++)
		    {
		    	_session.SessionData().getMasterServerSocketHandler().sendPacket(new UserJoinCustomRoomPacket(_session.getId(), Config._autojoinchannels[cc]));
		    }*/
			
			sendToClient(new EchoPacket(Config.GW_ECHO_NICK, "Pontos idő a Chat.hu szerveren: " + time));
			sendToClient(new LUsersPacket(sessionData.nick,sessionData.chatData.users.getUserNum()));
			
			
		}
		
	}

}